package com.kingdee.eas.hr.time.client;

import java.awt.Dialog;
import java.awt.Frame;
import java.awt.Window;
import java.awt.event.ActionEvent;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Map;

import javax.swing.DefaultComboBoxModel;
import javax.swing.SpinnerNumberModel;
import javax.swing.SwingUtilities;
import javax.swing.event.ChangeEvent;

import com.kingdee.bos.BOSException;
import com.kingdee.bos.ctrl.kdf.table.IRow;
import com.kingdee.bos.ctrl.kdf.table.KDTDefaultCellEditor;
import com.kingdee.bos.ctrl.kdf.table.KDTSortManager;
import com.kingdee.bos.ctrl.kdf.table.event.KDTEditEvent;
import com.kingdee.bos.ctrl.kdf.table.event.KDTMouseEvent;
import com.kingdee.bos.ctrl.kdf.table.event.KDTSelectEvent;
import com.kingdee.bos.ctrl.swing.KDComboBox;
import com.kingdee.bos.ctrl.swing.KDFormattedTextField;
import com.kingdee.bos.ctrl.swing.LanguageInfo;
import com.kingdee.bos.dao.IObjectPK;
import com.kingdee.bos.dao.ormapping.ObjectUuidPK;
import com.kingdee.bos.dao.query.IQueryExecutor;
import com.kingdee.bos.dao.query.QueryExecutorFactory;
import com.kingdee.bos.kscript.ParserException;
import com.kingdee.bos.kscript.runtime.Interpreter;
import com.kingdee.bos.kscript.runtime.InterpreterException;
import com.kingdee.bos.metadata.IMetaDataPK;
import com.kingdee.bos.metadata.MetaDataPK;
import com.kingdee.bos.metadata.entity.EntityViewInfo;
import com.kingdee.bos.metadata.entity.FilterInfo;
import com.kingdee.bos.metadata.entity.FilterItemInfo;
import com.kingdee.bos.metadata.query.util.CompareType;
import com.kingdee.bos.ui.util.UIHelper;
import com.kingdee.bos.util.BOSUuid;
import com.kingdee.eas.base.log.LogUtil;
import com.kingdee.eas.basedata.person.Genders;
import com.kingdee.eas.basedata.person.PersonCollection;
import com.kingdee.eas.basedata.person.PersonInfo;
import com.kingdee.eas.common.EASBizException;
import com.kingdee.eas.common.client.OprtState;
import com.kingdee.eas.common.client.SysContext;
import com.kingdee.eas.framework.FrameWorkUtils;
import com.kingdee.eas.framework.ICoreBase;
import com.kingdee.eas.hr.base.HRInitFactory;
import com.kingdee.eas.hr.base.IHRInit;
import com.kingdee.eas.hr.emp.client.EmployeeClientUtils;
import com.kingdee.eas.hr.emp.client.EmployeeMultiF7PromptBox;
import com.kingdee.eas.hr.time.ConvertMethodEnum;
import com.kingdee.eas.hr.time.ConvertTypeEnum;
import com.kingdee.eas.hr.time.IYearVacationBalance;
import com.kingdee.eas.hr.time.IYearVacationRule;
import com.kingdee.eas.hr.time.ObtainVacationDateEnum;
import com.kingdee.eas.hr.time.PrecisionTypeCarryEnum;
import com.kingdee.eas.hr.time.PrecisionTypeEnum;
import com.kingdee.eas.hr.time.ReservationTypeEnum;
import com.kingdee.eas.hr.time.ServiceYearTypeEnum;
import com.kingdee.eas.hr.time.UseVacationDateEnum;
import com.kingdee.eas.hr.time.YVRuleException;
import com.kingdee.eas.hr.time.YearVacationBalanceFactory;
import com.kingdee.eas.hr.time.YearVacationCarryforwardInfo;
import com.kingdee.eas.hr.time.YearVacationPersonCollection;
import com.kingdee.eas.hr.time.YearVacationPersonFactory;
import com.kingdee.eas.hr.time.YearVacationPersonInfo;
import com.kingdee.eas.hr.time.YearVacationQuantityInfo;
import com.kingdee.eas.hr.time.YearVacationRuleFactory;
import com.kingdee.eas.hr.time.YearVacationRuleInfo;
import com.kingdee.eas.util.SysUtil;
import com.kingdee.eas.util.client.EASResource;
import com.kingdee.eas.util.client.KDTableUtil;
import com.kingdee.eas.util.client.MsgBox;
import com.kingdee.jdbc.rowset.IRowSet;

public class YearVacationEditUI extends AbstractYearVacationEditUI {
	private static final long serialVersionUID = -3158950884675131214L;
	private static final String LIST = "list";
	private static final String RES = "com.kingdee.eas.hr.time.TimeResource";
	private YearVacationRuleInfo yearVacationRule = null;

	private ArrayList delList = new ArrayList();

	private String selectedID = null;

	public YearVacationEditUI() throws Exception {
	}

	public void onLoad() throws Exception {
		super.onLoad();
		initBaseInfo();
		initYearPerson();
		setInitState();
	}

	protected void setThelper() {
		setQueryPreference(true);
	}

	protected boolean isOrderByIDForBill() {
		return false;
	}

	private void initBaseInfo() throws Exception {
		this.txtName.setSelectedLanguage(new LanguageInfo(SysContext
				.getSysContext().getLocale()));

		SpinnerNumberModel model = (SpinnerNumberModel) this.spinnerPrecisionLength
				.getModel();

		model.setMaximum(new Integer(8));
		model.setMinimum(new Integer(0));

		model = (SpinnerNumberModel) this.kDSpinnerCarryPrecision.getModel();
		model.setMaximum(new Integer(8));

		model = (SpinnerNumberModel) this.kDSpinnerCarryPrecision.getModel();
		model.setMinimum(new Integer(0));

		model = (SpinnerNumberModel) this.kDSpinnerQuanAllDay.getModel();
		model.setMaximum(new Integer(31));

		model = (SpinnerNumberModel) this.kDSpinnerQuanAllDay.getModel();
		model.setMinimum(new Integer(0));

		this.kDSpinnerCarryPrecision.setValue(new Integer(2));
		this.kDSpinnerQuanAllDay.setValue(new Integer(0));
		this.spinnerPrecisionLength.setValue(new Integer(0));

		this.txtWorkTime.setDataType(4);
		this.txtWorkTime.setPrecision(1);
		this.txtWorkTime.setHorizontalAlignment(4);
		this.txtWorkTime.putClientProperty("OriginValue", Boolean.TRUE);
		this.txtWorkTime.setDataVerifierType(12);
		this.txtWorkTime.setMaximumValue(new Float(24.0D));
		this.txtWorkTime.setMinimumValue(new Float(0.0D));

		this.txtCarryObtainDays.setDataType(0);
		this.txtCarryObtainDays.setHorizontalAlignment(4);
		this.txtCarryObtainDays.putClientProperty("OriginValue", Boolean.TRUE);
		this.txtCarryObtainDays.setDataVerifierType(12);

		this.txtCarryObtainDays.setMaximumValue(new Integer(1000));
		this.txtCarryObtainDays.setMinimumValue(new Integer(0));
		this.txtCarryObtainDays.setGroupingUsed(false);

		this.txtCarryReservationValue.setDataType(4);
		this.txtCarryReservationValue.setPrecision(1);
		this.txtCarryReservationValue.setHorizontalAlignment(4);
		this.txtCarryReservationValue.putClientProperty("OriginValue",
				Boolean.TRUE);
		this.txtCarryReservationValue.setDataVerifierType(12);

		this.txtCarryReservationValue.setMaximumValue(new Float(1000.0D));
		this.txtCarryReservationValue.setMinimumValue(new Float(0.0D));
		this.txtCarryReservationValue.setGroupingUsed(false);

		this.tblAgeQuanSegment.checkParsed();
		KDFormattedTextField floatField = new KDFormattedTextField(4);

		floatField.setPrecision(3);
		floatField.setHorizontalAlignment(4);
		floatField.putClientProperty("OriginValue", Boolean.TRUE);

		floatField.setMinimumValue(new Float(0.0D));
		floatField.setMaximumValue(new Float(65535.0D));
		KDTDefaultCellEditor cellEditor = new KDTDefaultCellEditor(floatField);

		this.tblAgeQuanSegment.getColumn("colSegment").setEditor(cellEditor);

		floatField = new KDFormattedTextField(4);

		floatField.setPrecision(2);
		floatField.setMinimumValue(new Float(0.0D));
		floatField.setMaximumValue(new Float(65535.0D));
		this.tblAgeQuanSegment.getColumn("colCounts").setEditor(
				new KDTDefaultCellEditor(floatField));

		this.tblAgeQuanSegment.getColumn("colSign").getStyleAttributes()
				.setWeight(10.0F);

		loadAllEnumForComboBox();

		initSegmentTable();

		btnRadioQuanDay_stateChanged(null);
		btnRadioCarryNOTerm_stateChanged(null);
	}

	private void loadAllEnumForComboBox() {
		DefaultComboBoxModel model = null;
		Iterator ter = null;
		ter = ObtainVacationDateEnum.iterator();
		model = new DefaultComboBoxModel();
		while (ter.hasNext()) {
			model.addElement((ObtainVacationDateEnum) ter.next());
		}
		this.cboObtainVacationDate.setModel(model);

		model = new DefaultComboBoxModel();
		ter = UseVacationDateEnum.iterator();
		while (ter.hasNext()) {
			model.addElement((UseVacationDateEnum) ter.next());
		}
		this.cboUseVacationDate.setModel(model);

		model = new DefaultComboBoxModel();
		ter = ConvertMethodEnum.iterator();
		while (ter.hasNext()) {
			model.addElement((ConvertMethodEnum) ter.next());
		}
		this.cboQuanMonths.setModel(model);

		model = new DefaultComboBoxModel();
		ter = ServiceYearTypeEnum.iterator();
		while (ter.hasNext()) {
			model.addElement((ServiceYearTypeEnum) ter.next());
		}
		this.cboServiceYearType.setModel(model);

		model = new DefaultComboBoxModel();
		ter = PrecisionTypeCarryEnum.iterator();
		while (ter.hasNext()) {
			model.addElement((PrecisionTypeCarryEnum) ter.next());
		}
		this.cboCarryPrecisionType.setModel(model);

		model = new DefaultComboBoxModel();
		ter = ReservationTypeEnum.iterator();
		while (ter.hasNext()) {
			model.addElement((ReservationTypeEnum) ter.next());
		}
		this.cboCarryReservationType.setModel(model);

		DefaultComboBoxModel modelSign = new DefaultComboBoxModel();
		modelSign.addElement("<=");
		modelSign.addElement("<");
		modelSign.addElement("=");
		KDComboBox combo = new KDComboBox(modelSign);
		this.tblAgeQuanSegment.getColumn("colSign").setEditor(
				new KDTDefaultCellEditor(combo));
	}

	private void initYearPerson() throws Exception {
		this.tblPerson.checkParsed();
		this.tblPerson.getSelectManager().setSelectMode(2);

		this.tblPerson.getStyleAttributes().setLocked(true);

		KDTSortManager sortManager = new KDTSortManager(this.tblPerson);
		sortManager.setSortAuto(true);
		this.tblPerson.setSortMange(sortManager);
		int i = 0;
		for (int n = this.tblPerson.getColumnCount(); i < n; i++)
			this.tblPerson.getColumn(i).setSortable(true);
	}

	protected void initWorkButton() {
		super.initWorkButton();
		this.menuItemAddNew.setEnabled(true);
		this.menuItemEdit.setEnabled(true);
		this.menuItemRemove.setEnabled(true);
		setButtonDefaultStyl(this.btnSave);

		this.btnSave.setIcon(EASResource.getIcon("imgTbtn_save"));

		this.menuItemSave.setIcon(EASResource.getIcon("imgTbtn_save"));
		this.menuItemInitRule.setIcon(EASResource
				.getIcon("imgTbtn_ruleinitialize"));
	}

	private void setInitState() throws Exception {
		if (this.tblMain.getRowCount() > 0) {
			this.tblMain.getSelectManager().select(0, 0);
			diplayViewData();
		} else {
			setOprtState(OprtState.ADDNEW);

			createNewData();
			loadFields();
			btnRadioQuanDay_stateChanged(null);
			btnRadioCarryNOTerm_stateChanged(null);
		}
	}

	private void initSegmentTable() throws Exception {
		this.tblAgeQuanSegment.checkParsed();
		btnRadionQuanMonth_stateChanged(null);
		btnRadioCarryNOTerm_stateChanged(null);
	}

	private void createNewData() {
		this.yearVacationRule = new YearVacationRuleInfo();

		YearVacationQuantityInfo quantityInfo = new YearVacationQuantityInfo();
		quantityInfo.setObtainVacationDate(ObtainVacationDateEnum.ENTER_DATE);
		quantityInfo.setUseVacationDate(UseVacationDateEnum.ENTER_DATE);
		quantityInfo.setWorkTime(0.0F);
		quantityInfo.setVacationStartDate("01/01");
		quantityInfo.setServiceYearType(ServiceYearTypeEnum.COMPANY_YEARS);
		quantityInfo.setPrecisionLength(0);
		quantityInfo.setPrecisionType(PrecisionTypeEnum.EVERY_DAY);
		quantityInfo.setConvertTypeValue(0);
		quantityInfo.setConvertType(ConvertTypeEnum.EQUAL_DAY);
		this.yearVacationRule.setQuantity(quantityInfo);

		YearVacationCarryforwardInfo carryInfo = new YearVacationCarryforwardInfo();
		carryInfo.setReservationType(ReservationTypeEnum.FIX_DAYS);
		carryInfo.setPrecisionType(PrecisionTypeCarryEnum.FOUR_AND_FIVE);
		carryInfo.setAbandonDate(null);
		carryInfo.setObtainDays(0);
		carryInfo.setReservationValue(Float.valueOf("0").floatValue());
		this.yearVacationRule.setCarryforward(carryInfo);
	}

	public void loadFields() {
		try {
			this.txtNumber.setText(this.yearVacationRule.getNumber());
			UIHelper.loadMultiLangFields(this.txtName, this.yearVacationRule,
					"name");

			this.txtDesrc.setText(this.yearVacationRule.getDescription());

			loadQuantityFields(this.yearVacationRule.getQuantity());

			loadCarryforwardFields(this.yearVacationRule.getCarryforward());

			loadYVPersonFields(this.yearVacationRule);

			if (getOprtState().equals("list"))
				setPanelIsEnabled(false);
			else
				setPanelIsEnabled(true);
		} catch (Exception e) {
			handleException(e);
		}
	}

	private void loadQuantityFields(YearVacationQuantityInfo quantityInfo) {
		if (quantityInfo == null) {
			return;
		}

		if (quantityInfo.getVacationStartDate() == null)
			this.txtVacationStartDate.setText("");
		else {
			this.txtVacationStartDate.setText(quantityInfo
					.getVacationStartDate());
		}

		this.cboObtainVacationDate.setSelectedItem(quantityInfo
				.getObtainVacationDate());

		this.cboUseVacationDate.setSelectedItem(quantityInfo
				.getUseVacationDate());

		this.txtWorkTime.setValue(new Float(quantityInfo.getWorkTime()));

		if (quantityInfo.getPrecisionType() == PrecisionTypeEnum.EVERY_MONTH) {
			this.btnRadionQuanMonth.setSelected(true);
			this.btnRadioQuanDay.setSelected(false);
			if (quantityInfo.getConvertType() == ConvertTypeEnum.EQUAL_DAY) {
				this.btnRadioQuanAllDay.setSelected(true);
				this.btnRadioQuanMorths.setSelected(false);
			} else {
				this.btnRadioQuanAllDay.setSelected(false);
				this.btnRadioQuanMorths.setSelected(true);
			}
		} else {
			this.btnRadionQuanMonth.setSelected(false);
			this.btnRadioQuanDay.setSelected(true);
		}

		if ((quantityInfo.getConvertType() != null)
				&& (quantityInfo.getConvertType().getValue() == 10)) {
			this.kDSpinnerQuanAllDay.setValue(new Integer(quantityInfo
					.getConvertTypeValue()));

			this.btnRadioQuanAllDay.setSelected(true);
		} else if (quantityInfo.getConvertTypeValue() == 20) {
			this.cboQuanMonths.setSelectedItem(ConvertMethodEnum.EVERY_DAY);
			this.kDSpinnerQuanAllDay.setValue(new Integer(0));
		} else {
			this.cboQuanMonths.setSelectedItem(ConvertMethodEnum.STANDARD_DAY);
		}

		this.spinnerPrecisionLength.setValue(new Integer(quantityInfo
				.getPrecisionLength()));

		this.kDCheckBox1.setSelected(quantityInfo.isIsChecked());

		this.cboServiceYearType.setSelectedItem(quantityInfo
				.getServiceYearType());

		loadSegmentTable(quantityInfo);
	}

	private void loadSegmentTable(YearVacationQuantityInfo quantityInfo) {
		if ((quantityInfo.getServiceYearSet() == null)
				|| (quantityInfo.getServiceYearSet().equals(""))) {
			this.tblAgeQuanSegment.removeRows();
			return;
		}
		this.tblAgeQuanSegment.removeRows();
		
		String strExt = quantityInfo.getExtVacationSet();
		String[] extItems = strExt.split("&");

		String[] items = quantityInfo.getServiceYearSet().split("&");
		IRow curRow = null;
		String[] subItems = null;
		String[] subItemss = null;

		String[] extSubItems = null;
		String[] extSubItemss = null;
		for (int i = 0; i < items.length; i++) {
			curRow = this.tblAgeQuanSegment.addRow();
			subItems = items[i].split("=");
			extSubItems = extItems[i].split("=");
			if ((subItems.length == 2) && (items[i].indexOf("_") == -1)) {
				curRow.getCell("colSign").setValue("<=");

				curRow.getCell("colSegment").setValue(
						new Float(subItems[0].trim()));

				curRow.getCell("colYearVacation").setValue(
						new Float(subItems[1].trim()));
				curRow.getCell("colExtVacation").setValue(
						new Float(extSubItems[1].trim()));
				curRow.getCell("colCounts").setValue(
						new Float(extSubItems[1].trim())
								+ new Float(subItems[1].trim()));
			}

			if (items[i].indexOf("_") == -1)
				continue;
			subItemss = items[i].split("_");
			extSubItemss = extItems[i].split("_");
			if (subItemss.length == 3) {
				if (subItemss[0].trim().equals("==")) {
					curRow.getCell("colSign").setValue("=");
				} else {
					curRow.getCell("colSign").setValue(subItemss[0].trim());
				}

				curRow.getCell("colSegment").setValue(
						new Float(subItemss[1].trim()));

				curRow.getCell("colYearVacation").setValue(
						new Float(subItemss[2].trim()));
				curRow.getCell("colExtVacation").setValue(
						new Float(extSubItemss[2].trim()));
				curRow.getCell("colCounts").setValue(
						new Float(subItemss[2].trim())
								+ new Float(extSubItemss[2].trim()));
			}
		}

		Interpreter interpreter = new Interpreter();

		Map context = new HashMap();

		context.put("list", new Float(2.3D));

		String text = "if(list<1){return 5.5;}if(list<3){return 7.6;}if(list<5){return 10.2;}";
		try {
			Object rtnValue = interpreter.eval(text, context);
		} catch (InterpreterException e) {
			e.printStackTrace();
		} catch (ParserException e) {
			e.printStackTrace();
		}
	}

	private void loadCarryforwardFields(YearVacationCarryforwardInfo vyCarryInfo) {
		if (vyCarryInfo == null) {
			return;
		}

		if (vyCarryInfo.isIsAbandon()) {
			this.btnRadioCarryNOTerm.setSelected(false);
			this.btnRadioCarryYesTerm.setSelected(true);

			this.cboCarryReservationType.setSelectedItem(vyCarryInfo
					.getReservationType());

			this.txtCarryReservationValue.setValue(new Float(vyCarryInfo
					.getReservationValue()));

			this.txtCarryAbandonDate.setText(vyCarryInfo.getAbandonDate());

			this.txtCarryObtainDays.setValue(new Integer(0));
			this.kDSpinnerCarryPrecision.setValue(new Integer(0));
			this.cboCarryPrecisionType
					.setSelectedItem(PrecisionTypeEnum.EVERY_DAY);
		} else {
			this.btnRadioCarryNOTerm.setSelected(true);
			this.btnRadioCarryYesTerm.setSelected(false);
			this.txtCarryObtainDays.setValue(new Integer(vyCarryInfo
					.getObtainDays()));

			this.kDSpinnerCarryPrecision.setValue(new Integer(vyCarryInfo
					.getPrecision()));

			this.cboCarryPrecisionType.setSelectedItem(vyCarryInfo
					.getPrecisionType());

			this.cboCarryReservationType
					.setSelectedItem(ReservationTypeEnum.FIX_DAYS);

			this.txtCarryReservationValue.setValue(new Float("0.0"));
			this.txtCarryAbandonDate.setText(null);
		}
	}

	private void setPanelIsEnabled(boolean isEnabled) {
		this.btnRadioCarryNOTerm.setEnabled(isEnabled);
		this.btnRadioCarryYesTerm.setEnabled(isEnabled);
		this.btnRadionQuanMonth.setEnabled(isEnabled);
		this.btnRadioQuanAllDay.setEnabled(isEnabled);
		this.btnRadioQuanDay.setEnabled(isEnabled);
		this.btnRadioQuanMorths.setEnabled(isEnabled);
		this.txtCarryAbandonDate.setEnabled(isEnabled);

		this.txtCarryReservationValue.setEnabled(isEnabled);
		this.txtDesrc.setEnabled(isEnabled);
		this.txtName.setEnabled(isEnabled);
		this.txtNumber.setEnabled(isEnabled);
		this.txtWorkTime.setEnabled(isEnabled);

		this.tblAgeQuanSegment.setEnabled(isEnabled);
		this.tblPerson.setEnabled(isEnabled);
		this.btnWorkInsert.setEnabled(isEnabled);
		this.btnWorkDelete.setEnabled(isEnabled);
		this.btnWorkDeleteYear.setEnabled(isEnabled);
		this.btnWorkInsertYear.setEnabled(isEnabled);

		this.spinnerPrecisionLength.setEnabled(isEnabled);

		this.kDCheckBox1.setEnabled(isEnabled);

		this.kDSpinnerCarryPrecision.setEnabled(isEnabled);
		this.kDSpinnerQuanAllDay.setEnabled(isEnabled);

		this.cboCarryPrecisionType.setEnabled(isEnabled);
		this.cboCarryReservationType.setEnabled(isEnabled);
		this.cboObtainVacationDate.setEnabled(isEnabled);
		this.cboQuanMonths.setEnabled(isEnabled);
		this.cboServiceYearType.setEnabled(isEnabled);
		this.cboUseVacationDate.setEnabled(isEnabled);
		this.txtCarryObtainDays.setEnabled(isEnabled);
	}

	private void storeSegment() {
		YearVacationQuantityInfo quantityInfo = this.yearVacationRule
				.getQuantity();

		StringBuffer strBuffer = new StringBuffer();
		StringBuffer strExtBuffer = new StringBuffer();

		String strSegment = null;
		String strYearVacation = null;
		String strExt = null;

		String colSign = null;

		int i = 0;
		for (int n = this.tblAgeQuanSegment.getRowCount(); i < n; i++) {
			if ((this.tblAgeQuanSegment.getRow(i).getCell("colSegment")
					.getValue() == null)
					|| (this.tblAgeQuanSegment.getRow(i).getCell(
							"colYearVacation").getValue() == null)) {
				continue;
			}
			strSegment = this.tblAgeQuanSegment.getRow(i).getCell("colSegment")
					.getValue().toString();

			strYearVacation = this.tblAgeQuanSegment.getRow(i).getCell(
					"colYearVacation").getValue().toString();

			strExt = this.tblAgeQuanSegment.getRow(i).getCell("colExtVacation")
					.getValue() == null ? "0" : this.tblAgeQuanSegment
					.getRow(i).getCell("colExtVacation").getValue().toString();

			colSign = this.tblAgeQuanSegment.getRow(i).getCell("colSign")
					.getValue().toString();

			if ((strSegment.trim().equals(""))
					|| (strYearVacation.trim().equals(""))) {
				continue;
			}
			if (colSign.trim().equals("=")) {
				strBuffer.append("== _ ");
				strExtBuffer.append("== _ ");
			} else {
				strBuffer.append(colSign + " _ ");
				strExtBuffer.append(colSign + " _ ");
			}

			strBuffer.append(strSegment + " _ " + strYearVacation);
			strBuffer.append(" & ");
			strExtBuffer.append(strSegment + " _ " + strExt);
			strExtBuffer.append(" & ");
		}

		quantityInfo.setServiceYearSet(strBuffer.toString().trim());
		quantityInfo.setExtVacationSet(strExtBuffer.toString().trim());
	}

	private void loadPersons(YearVacationRuleInfo ruleInfo) throws BOSException {
		YearVacationPersonCollection yearVactionPersonColl = ruleInfo
				.getPersons();

		yearVactionPersonColl.clear();

		EntityViewInfo viewInfo = new EntityViewInfo();
		FilterInfo filter = new FilterInfo();
		filter.getFilterItems().add(
				new FilterItemInfo("yvRule.id", ruleInfo.getId().toString()));

		viewInfo.setFilter(filter);

		IMetaDataPK queryPK = new MetaDataPK("com.kingdee.eas.hr.time.app",
				"YearPersonQuery");

		IQueryExecutor iqexec = getQueryExecutor(queryPK, viewInfo);

		IRowSet rowSet = iqexec.executeQuery();

		YearVacationPersonInfo yearVactationPersonInfo = null;
		PersonInfo person = null;
		String ID = null;
		String personID = null;
		String gender = null;
		try {
			while (rowSet.next()) {
				yearVactationPersonInfo = new YearVacationPersonInfo();

				ID = rowSet.getString("id");
				yearVactationPersonInfo.setId(BOSUuid.read(ID));

				personID = rowSet.getString("person.id");

				person = new PersonInfo();
				person.setId(BOSUuid.read(personID));
				person.put("primaryAdminOrg", rowSet
						.getString("AdminOrgUnit.displayName"));

				person
						.put("primaryPosition", rowSet
								.getString("Position.name"));

				person.put("YVId", rowSet.getString("id"));
				person.put("YVName", rowSet.getString("yvRule.name"));
				person.put("YVNumber", rowSet.getString("yvRule.number"));
				person.setNumber(rowSet.getString("person.number"));
				person.setName(rowSet.getString("person.name"));

				gender = rowSet.getString("person.gender");
				if (gender != null) {
					if (Genders.Male.toString().equals(gender))
						person.setGender(Genders.Male);
					else {
						person.setGender(Genders.Female);
					}
				}
				yearVactationPersonInfo.setPerson(person);
				yearVactationPersonInfo.setYvRule(ruleInfo);
				yearVactionPersonColl.add(yearVactationPersonInfo);
			}
		} catch (Exception ex) {
			super.handleException(ex);
		}
	}

	private void loadYVPersonFields(YearVacationRuleInfo ruleInfo)
			throws Exception {
		this.tblPerson.removeRows();
		YearVacationPersonCollection yearVactionPersonColl = ruleInfo
				.getPersons();

		if ((yearVactionPersonColl == null)
				|| (yearVactionPersonColl.size() == 0)) {
			return;
		}
		int counts = yearVactionPersonColl.size();

		YearVacationPersonInfo yvPersonInfo = null;
		PersonInfo person = null;
		IRow curRow = null;
		for (int i = 0; i < counts; i++) {
			yvPersonInfo = yearVactionPersonColl.get(i);
			person = yvPersonInfo.getPerson();
			curRow = this.tblPerson.addRow();
			curRow.getCell("itemId").setValue(yvPersonInfo.getId());
			curRow.getCell("id").setValue(person.getId().toString());
			curRow.getCell("colNumber").setValue(person.getNumber());
			curRow.getCell("colName").setValue(person.getName());
			curRow.getCell("colSex").setValue(person.getGender());
			curRow.getCell("colOrg").setValue(person.get("primaryAdminOrg"));
			curRow.getCell("colPosition").setValue(
					person.get("primaryPosition"));

			curRow.getCell("colSourceID").setValue(person.get("YVId"));
			curRow.getCell("colSourceName").setValue(person.get("YVName"));
			curRow.getCell("colSourceNumber").setValue(person.get("YVNumber"));
		}
	}

	private PersonCollection getPersonYVInfo(PersonCollection pInfos)
			throws Exception {
		PersonInfo newInfo = null;
		Map personToCollectionMap = new HashMap();
		HashSet set = new HashSet();
		int i = 0;
		for (int n = pInfos.size(); i < n; i++) {
			newInfo = pInfos.get(i);
			personToCollectionMap.put(newInfo.getId().toString(), "" + i);
			set.add(newInfo.getId().toString());

			newInfo.put("YVName", null);
			newInfo.put("YVId", null);
			newInfo.put("YVNumber", null);
			newInfo.put("yvRuleId", null);
			pInfos.add(newInfo);
		}

		MetaDataPK queryPK = new MetaDataPK("com.kingdee.eas.hr.time.app",
				"PersonToYVQuery");

		IQueryExecutor exec = QueryExecutorFactory.getRemoteInstance(queryPK);

		EntityViewInfo evi = new EntityViewInfo();
		FilterInfo fi = new FilterInfo();
		fi.getFilterItems().add(
				new FilterItemInfo("person.id", set, CompareType.INCLUDE));

		evi.setFilter(fi);
		exec.setObjectView(evi);
		IRowSet rowSet = exec.executeQuery();
		String personId = null;

		while (rowSet.next()) {
			personId = rowSet.getString("person.id");
			newInfo = pInfos.get(Integer.parseInt(personToCollectionMap.get(
					personId).toString()));

			newInfo.put("YVName", rowSet.getString("yvRule.name"));
			newInfo.put("YVId", rowSet.getString("id"));
			newInfo.put("YVNumber", rowSet.getString("yvRule.number"));
			newInfo.put("yvRuleId", rowSet.getString("yvRule.id"));
		}

		return pInfos;
	}

	private void storeYVPersonFields() {
		YearVacationPersonCollection yearPersonColl = this.yearVacationRule
				.getPersons();
		try {
			YearVacationPersonInfo yvPersonInfo = null;
			int i = 0;
			for (int n = this.tblPerson.getRowCount(); i < n; i++) {
				if (this.tblPerson.getRow(i).getCell("itemId").getValue() == null) {
					yvPersonInfo = new YearVacationPersonInfo();
					PersonInfo personInfo = new PersonInfo();
					personInfo.setId(BOSUuid.read(this.tblPerson.getRow(i)
							.getCell("id").getValue().toString()));

					if (this.tblPerson.getRow(i).getCell("colSourceID")
							.getValue() != null) {
						personInfo.put("YVId", this.tblPerson.getRow(i)
								.getCell("colSourceID").getValue().toString());
					} else {
						personInfo.put("YVId", null);
					}
					yvPersonInfo.setPerson(personInfo);

					yearPersonColl.add(yvPersonInfo);
				}
			}

			for (int k = 0; k < this.delList.size(); k++)
				for (int j = 0; j < yearPersonColl.size(); j++) {
					if ((yearPersonColl.get(j).getId() == null)
							|| (!((String) this.delList.get(k))
									.equals(yearPersonColl.get(j).getId()
											.toString()))) {
						continue;
					}
					yearPersonColl.removeObject(j);
				}
		} catch (Exception e) {
			handleException(e);
		}
	}

	private void storeYVCarryforwardFields() {
		YearVacationCarryforwardInfo carryInfo = this.yearVacationRule
				.getCarryforward();

		if (this.btnRadioCarryNOTerm.isSelected()) {
			carryInfo.setIsAbandon(Boolean.FALSE.booleanValue());

			String ObtainDays = null;
			if ((this.txtCarryObtainDays.getText() != null)
					&& (this.txtCarryObtainDays.getText().trim().length() > 0)) {
				ObtainDays = this.txtCarryObtainDays.getText();
				if (ObtainDays.indexOf(".") != -1) {
					ObtainDays = ObtainDays.substring(0,
							this.txtCarryObtainDays.getText().indexOf("."));
				}
				carryInfo.setObtainDays(Integer.parseInt(ObtainDays));
			} else {
				carryInfo.setObtainDays(Integer.parseInt("0"));
			}

			carryInfo.setPrecision(this.kDSpinnerCarryPrecision
					.getIntegerVlaue().intValue());

			carryInfo
					.setPrecisionType((PrecisionTypeCarryEnum) this.cboCarryPrecisionType
							.getSelectedItem());
		} else {
			carryInfo.setIsAbandon(Boolean.TRUE.booleanValue());

			carryInfo.setAbandonDate(this.txtCarryAbandonDate.getText());

			carryInfo
					.setReservationType((ReservationTypeEnum) this.cboCarryReservationType
							.getSelectedItem());

			if ((this.txtCarryReservationValue.getText() != null)
					&& (!this.txtCarryReservationValue.getText().equals(""))
					&& (this.txtCarryReservationValue.getText().trim().length() != 0)) {
				carryInfo.setReservationValue(Float
						.parseFloat(this.txtCarryReservationValue.getText()));
			} else
				carryInfo.setReservationValue(Float.parseFloat("0"));
		}
	}

	public void storeFields() {
		storeYVPersonFields();
	}

	private void storeYVQuantityFields() {
		YearVacationQuantityInfo quantityInfo = this.yearVacationRule
				.getQuantity();

		quantityInfo.setVacationStartDate(this.txtVacationStartDate.getText());

		quantityInfo
				.setObtainVacationDate((ObtainVacationDateEnum) this.cboObtainVacationDate
						.getSelectedItem());

		quantityInfo
				.setUseVacationDate((UseVacationDateEnum) this.cboUseVacationDate
						.getSelectedItem());

		if ((this.txtWorkTime.getText() == null)
				|| (this.txtWorkTime.getText().trim().length() == 0)) {
			quantityInfo.setWorkTime(Float.parseFloat("0"));
		} else {
			quantityInfo.setWorkTime(Float.parseFloat(this.txtWorkTime
					.getText()));
		}

		if (this.btnRadionQuanMonth.isSelected()) {
			quantityInfo.setPrecisionType(PrecisionTypeEnum.EVERY_MONTH);
			if (this.btnRadioQuanAllDay.isSelected()) {
				quantityInfo.setConvertType(ConvertTypeEnum.EQUAL_DAY);
				quantityInfo.setConvertTypeValue(this.kDSpinnerQuanAllDay
						.getIntegerVlaue().intValue());
			} else {
				quantityInfo.setConvertType(ConvertTypeEnum.CONVERT_MONTHS);
				quantityInfo
						.setConvertTypeValue(((ConvertMethodEnum) this.cboQuanMonths
								.getSelectedItem()).getValue());
			}

		} else {
			quantityInfo.setConvertType(ConvertTypeEnum.CONVERT_MONTHS);
			quantityInfo.setConvertTypeValue(0);
			quantityInfo.setPrecisionType(PrecisionTypeEnum.EVERY_DAY);
		}

		quantityInfo.setPrecisionLength(this.spinnerPrecisionLength
				.getIntegerVlaue().intValue());

		quantityInfo.setIsChecked(this.kDCheckBox1.isSelected());

		quantityInfo
				.setServiceYearType((ServiceYearTypeEnum) this.cboServiceYearType
						.getSelectedItem());

		storeSegment();
	}

	protected void tblMain_tableClicked(KDTMouseEvent e) throws Exception {
	}

	protected void tblMain_tableSelectChanged(KDTSelectEvent e) {
		if (getSelectedKeyValue() != null) {
			this.btnSave.setEnabled(false);
			try {
				diplayViewData();
			} catch (Exception e1) {
				handUIException(e1);
			}
		}
	}

	private void diplayViewData() throws Exception {
		setOprtState("list");
		this.btnSave.setEnabled(false);
		this.actionSave.setEnabled(false);
		this.actionAddNew.setEnabled(true);
		this.actionEdit.setEnabled(true);
		this.actionRemove.setEnabled(true);
		getSelectRuleValue();
		loadFields();
	}

	public void actionAddNew_actionPerformed(ActionEvent e) throws Exception {
		setOprtState(OprtState.ADDNEW);
		this.btnSave.setEnabled(true);

		this.actionInitRule.setEnabled(false);
		createNewData();
		loadFields();
		btnRadioQuanDay_stateChanged(null);
		btnRadioCarryNOTerm_stateChanged(null);
	}

	public void actionView_actionPerformed(ActionEvent e) throws Exception {
		diplayViewData();
	}

	public void actionEdit_actionPerformed(ActionEvent e) throws Exception {
		checkSelected();
		setOprtState(OprtState.EDIT);
		this.actionSave.setEnabled(true);
		this.actionEdit.setEnabled(false);
		this.btnSave.setEnabled(true);
		this.btnEdit.setEnabled(false);
		getSelectRuleValue();
		loadFields();
		btnRadioQuanMorths_stateChanged(null);
		btnRadioCarryNOTerm_stateChanged(null);
		btnRadioCarryYesTerm_stateChanged(null);
		btnRadioQuanAllDay_stateChanged(null);
		btnRadioQuanDay_stateChanged(null);
	}

	public void actionRemove_actionPerformed(ActionEvent e) throws Exception {
		super.actionRemove_actionPerformed(e);
		if (getSelectedKeyValue() != null) {
			diplayViewData();
		} else {
			setOprtState(OprtState.ADDNEW);

			createNewData();
			loadFields();
			btnRadioQuanDay_stateChanged(null);
			btnRadioCarryNOTerm_stateChanged(null);
		}
	}

	private void getSelectRuleValue() throws BOSException, EASBizException {
		String id = super.getSelectedKeyValue();
		if (id != null) {
			IYearVacationRule iRule = YearVacationRuleFactory
					.getRemoteInstance();

			this.yearVacationRule = iRule.getSimpleValue(id);
			loadPersons(this.yearVacationRule);

			this.actionInitRule.setEnabled(true);
		} else {
			this.actionInitRule.setEnabled(false);
		}
		this.selectedID = id;
	}

	public void actionSave_actionPerformed(ActionEvent e) throws Exception {
		this.yearVacationRule.setNumber(this.txtNumber.getText());
		UIHelper.storeMultiLangFields(this.txtName, this.yearVacationRule,
				"name");
		this.yearVacationRule.setDescription(this.txtDesrc.getText());

		storeYVQuantityFields();

		storeYVCarryforwardFields();
		checkInput();
		storeFields();

		IYearVacationRule iRule = YearVacationRuleFactory.getRemoteInstance();
		if ((this.yearVacationRule != null)
				&& (this.yearVacationRule.getId() != null)
				&& (getOprtState().equals(OprtState.EDIT))) {
			iRule.update(new ObjectUuidPK(this.yearVacationRule.getId()),
					this.yearVacationRule);
		} else {
			this.yearVacationRule.setHrOrgUnit(SysContext.getSysContext()
					.getCurrentHRUnit());

			IObjectPK pk = iRule.addnew(this.yearVacationRule);
			this.yearVacationRule.setId(BOSUuid.read(pk.toString()));
		}

		showSubmitSuccess();
		setOprtState("list");
		this.actionSave.setEnabled(false);
		this.actionEdit.setEnabled(true);
		this.btnSave.setEnabled(false);
		this.btnEdit.setEnabled(true);
		refreshList();
		setPanelIsEnabled(false);
	}

	private void checkInput() throws YVRuleException {
		if (this.yearVacationRule == null)
			return;
		if ((this.yearVacationRule.getNumber() == null)
				|| (this.yearVacationRule.getNumber().length() == 0)) {
			throw new YVRuleException(YVRuleException.RULE_NUMBER_NOT_NULL);
		}
		if ((this.yearVacationRule.getName() == null)
				|| (this.yearVacationRule.getName().length() == 0)) {
			throw new YVRuleException(YVRuleException.RULE_NAME_NOT_NULL);
		}

		if ((this.yearVacationRule.getQuantity() == null)
				|| (this.yearVacationRule.getQuantity().getVacationStartDate() == null)
				|| (this.yearVacationRule.getQuantity().getVacationStartDate()
						.length() == 0)
				|| (this.yearVacationRule.getQuantity().getVacationStartDate()
						.equals("/"))) {
			throw new YVRuleException(YVRuleException.STARTDATE_NOT_NULL);
		}

		if ((this.yearVacationRule.getQuantity() == null)
				|| (this.yearVacationRule.getQuantity().getObtainVacationDate() == null)) {
			throw new YVRuleException(YVRuleException.YV_STARTDATE_NOT_NULL);
		}
		if ((this.yearVacationRule.getQuantity() == null)
				|| (this.yearVacationRule.getQuantity().getObtainVacationDate() == null)) {
			throw new YVRuleException(YVRuleException.VACATIONDATE_NOT_NULL);
		}
		if ((this.yearVacationRule.getQuantity() == null)
				|| (this.yearVacationRule.getQuantity().getUseVacationDate() == null)) {
			throw new YVRuleException(YVRuleException.UV_DATE_NOT_NULL);
		}
		if (this.spinnerPrecisionLength.getValue() == null) {
			throw new YVRuleException(YVRuleException.PRECISIONLENGTH_NOT_NULL);
		}

		checkTableInput();
	}

	public void beforeActionPerformed(ActionEvent e) {
		try {
			super.beforeActionPerformed(e);
		} catch (Exception ex) {
			handleException(ex);
		}
	}

	private void checkTableInput() throws YVRuleException {
		int counts = this.tblAgeQuanSegment.getRowCount();
		if (counts == 0) {
			throw new YVRuleException(YVRuleException.MUST_ONE_ROW_SEGMENT);
		}
		BigDecimal segCounts = null;
		BigDecimal iCounts = null;
		BigDecimal segOldCounts = null;
		BigDecimal iOldCounts = null;
		for (int i = 0; i < counts; i++)
			if ((this.tblAgeQuanSegment.getRow(i).getCell("colSegment")
					.getValue() != null)
					&& (this.tblAgeQuanSegment.getRow(i).getCell("colCounts")
							.getValue() != null)) {
				segCounts = new BigDecimal(this.tblAgeQuanSegment.getRow(i)
						.getCell("colSegment").getValue().toString());

				iCounts = new BigDecimal(this.tblAgeQuanSegment.getRow(i)
						.getCell("colCounts").getValue().toString());

				if (segCounts.compareTo(new BigDecimal("999")) > 0) {
					throw new YVRuleException(YVRuleException.SEGMENT_NOT_RIGHT);
				}
				if (iCounts.compareTo(new BigDecimal("100")) > 0) {
					throw new YVRuleException(YVRuleException.GET_DAYS_TIMES);
				}

				if (i != 0) {
					segOldCounts = new BigDecimal(this.tblAgeQuanSegment
							.getRow(i - 1).getCell("colSegment").getValue()
							.toString());

					iOldCounts = new BigDecimal(this.tblAgeQuanSegment.getRow(
							i - 1).getCell("colCounts").getValue().toString());

					if (segOldCounts.compareTo(segCounts) > 0) {
						throw new YVRuleException(
								YVRuleException.MUST_LESS_NEXT_ROW);
					}

					if (segOldCounts.compareTo(segCounts) != 0)
						continue;
					if ((this.tblAgeQuanSegment.getRow(i - 1)
							.getCell("colSign").getValue().toString()
							.equals("<"))
							&& (this.tblAgeQuanSegment.getRow(i).getCell(
									"colSign").getValue().toString()
									.equals("="))) {
						continue;
					}

					throw new YVRuleException(
							YVRuleException.MUST_LESS_NEXT_ROW1);
				}

			} else {
				throw new YVRuleException(
						YVRuleException.MUST_INPUT_SEGMENT_ALL);
			}
	}

	protected void showSubmitSuccess() {
		setMessageText(getClassAlise()
				+ " "
				+ EASResource
						.getString("com.kingdee.eas.framework.FrameWorkResource.Msg_Save_OK"));

		showMessage();
	}

	private String getClassAlise() {
		String className = FrameWorkUtils.getClassAlias(this.yearVacationRule);

		return className;
	}

	protected String getEditUIName() {
		return null;
	}

	protected ICoreBase getBizInterface() throws Exception {
		return YearVacationRuleFactory.getRemoteInstance();
	}

	public void initUIToolBarLayout() {
		super.initUIToolBarLayout();
		this.actionSave.setEnabled(true);

		this.actionInitRule.setEnabled(false);
		EmployeeClientUtils
				.initTableBtn(this.btnWorkInsert, this.btnWorkDelete);
		this.btnWorkInsert.setIcon(EASResource.getIcon("imgTbtn_userview"));
		this.btnWorkInsert.setText(null);
		this.btnWorkDelete.setIcon(EASResource.getIcon("imgTbtn_logoutuser"));
		this.btnWorkDelete.setText(null);
		this.btnInitRule.setIcon(EASResource.getIcon("imgTbtn_ruleinitialize"));
		EmployeeClientUtils.initTableBtn(this.btnWorkInsertYear,
				this.btnWorkDeleteYear);
	}

	public void actionDeleteYear_actionPerformed(ActionEvent e)
			throws Exception {
		int selectRow = KDTableUtil.getSelectedRow(this.tblAgeQuanSegment);
		if (selectRow != -1)
			this.tblAgeQuanSegment.removeRow(selectRow);
	}

	public void actionInsertYear_actionPerformed(ActionEvent e)
			throws Exception {
		IRow curRow = this.tblAgeQuanSegment.addRow();
		curRow.getCell("colSign").setValue("<=");
	}

	protected void btnRadionQuanMonth_stateChanged(ChangeEvent e)
			throws Exception {
		if (this.btnRadionQuanMonth.isSelected()) {
			this.btnRadioQuanMorths.setEnabled(true);
			this.btnRadioQuanAllDay.setEnabled(true);
			this.kDSpinnerQuanAllDay.setEnabled(true);
		}
	}

	protected void btnRadioQuanAllDay_stateChanged(ChangeEvent e)
			throws Exception {
		if (this.btnRadioQuanAllDay.isSelected()) {
			this.cboQuanMonths.setEnabled(false);
			this.kDSpinnerQuanAllDay.setEnabled(true);
		}
	}

	protected void btnRadioCarryNOTerm_stateChanged(ChangeEvent e)
			throws Exception {
		if (this.btnRadioCarryNOTerm.isSelected()) {
			this.txtCarryObtainDays.setEnabled(true);
			this.cboCarryPrecisionType.setEnabled(true);
			this.kDSpinnerCarryPrecision.setEnabled(true);
			this.txtCarryAbandonDate.setEnabled(false);
			this.cboCarryReservationType.setEnabled(false);
			this.txtCarryReservationValue.setEnabled(false);
		}
	}

	protected void btnRadioCarryYesTerm_stateChanged(ChangeEvent e)
			throws Exception {
		if (this.btnRadioCarryYesTerm.isSelected()) {
			this.txtCarryObtainDays.setEnabled(false);
			this.cboCarryPrecisionType.setEnabled(false);
			this.kDSpinnerCarryPrecision.setEnabled(false);
			this.txtCarryAbandonDate.setEnabled(true);
			this.cboCarryReservationType.setEnabled(true);
			this.txtCarryReservationValue.setEnabled(true);
		}
	}

	protected void btnRadioQuanDay_stateChanged(ChangeEvent e) throws Exception {
		if (this.btnRadioQuanDay.isSelected()) {
			this.btnRadioQuanMorths.setEnabled(false);
			this.btnRadioQuanAllDay.setEnabled(false);
			this.cboQuanMonths.setEnabled(false);
			this.kDSpinnerQuanAllDay.setValue(new Integer(0));
			this.kDSpinnerQuanAllDay.setEnabled(false);
		}
	}

	protected void btnRadioQuanMorths_stateChanged(ChangeEvent e)
			throws Exception {
		if (this.btnRadioQuanMorths.isSelected()) {
			this.cboQuanMonths.setEnabled(true);
			this.kDSpinnerQuanAllDay.setEnabled(false);
		}
	}

	protected void btnWorkDelete_actionPerformed(ActionEvent e)
			throws Exception {
		int selectRow = KDTableUtil.getSelectedRow(this.tblPerson);
		if (selectRow != -1) {
			if (confirmRemove()) {
				if (this.tblPerson.getRow(selectRow).getCell("itemId")
						.getValue() != null) {
					this.delList.add(this.tblPerson.getRow(selectRow).getCell(
							"itemId").getValue().toString());
				}

				this.tblPerson.removeRow(selectRow);
			}
		} else {
			MsgBox.showWarning(this, EASResource.getString(
					"com.kingdee.eas.hr.time.TIMEAutoGenerateResource",
					"79_YearVacationEditUI"));
		}
	}

	protected void btnWorkInsert_actionPerformed(ActionEvent e)
			throws Exception {
		EmployeeMultiF7PromptBox personPrompt = new EmployeeMultiF7PromptBox(
				this);

		personPrompt.setIsSingleSelect(false);
		personPrompt.setModal(true);

		personPrompt.setIsPluralityIsChooseContral(false);

		personPrompt.show();

		if (personPrompt.isCanceled()) {
			return;
		}

		if ((personPrompt.getData() instanceof Object[])) {
			Object[] obj = (Object[]) personPrompt.getData();

			PersonCollection personCollection = new PersonCollection();
			int i = 0;
			for (int n = obj.length; i < n; i++) {
				personCollection.add((PersonInfo) obj[i]);
			}
			PersonCollection pInfos = getPersonYVInfo(personCollection);

			int counts = pInfos.size();
			PersonInfo infoPerson = null;
			int existCounts = 0;
			StringBuffer sb = new StringBuffer();
			for (int j = 0; j < counts; j++) {
				infoPerson = pInfos.get(j);
				if ((infoPerson.get("YVId") == null)
						|| (this.selectedID.equals(infoPerson.get("yvRuleId"))))
					continue;
				sb.append(infoPerson.getName());
				sb.append(",");
				existCounts++;
			}

			if (existCounts > 0) {
				int con = MsgBox.showConfirm2(sb.substring(0, sb.length() - 1)
						+ EASResource.getString(
								"com.kingdee.eas.hr.time.TimeResource",
								"otherRule"));

				if (con != 0) {
					for (int j = counts - 1; j >= 0; j--) {
						infoPerson = pInfos.get(j);
						if (infoPerson.get("YVId") != null) {
							pInfos.remove(infoPerson);
						}
					}
				}
			}

			for (int j = 0; j < pInfos.size(); j++) {
				infoPerson = pInfos.get(j);
				addPersonInfo(infoPerson);
			}
		}
	}

	private void addPersonInfo(PersonInfo infoPerson) {
		if (!checkExistInTable(infoPerson)) {
			IRow curRow = this.tblPerson.addRow();
			curRow.getCell("id").setValue(infoPerson.getId().toString());
			curRow.getCell("colNumber").setValue(infoPerson.getNumber());
			curRow.getCell("colName").setValue(infoPerson.getName());
			curRow.getCell("colSex").setValue(infoPerson.getGender());
			curRow.getCell("colOrg")
					.setValue(infoPerson.get("primaryAdminOrg"));

			curRow.getCell("colPosition").setValue(
					infoPerson.get("primaryPosition"));

			curRow.getCell("colSourceID").setValue(infoPerson.get("YVId"));
			curRow.getCell("colSourceName").setValue(infoPerson.get("YVName"));
			curRow.getCell("colSourceNumber").setValue(
					infoPerson.get("YVNumber"));
		}
	}

	private boolean checkExistInTable(PersonInfo pInfo) {
		int counts = this.tblPerson.getRowCount();
		boolean isExist = false;
		for (int i = 0; i < counts; i++) {
			if (!pInfo.getId().toString().equals(
					this.tblPerson.getRow(i).getCell("id").getValue()
							.toString()))
				continue;
			isExist = true;
			break;
		}

		return isExist;
	}

	public void actionInitRule_actionPerformed(ActionEvent e) throws Exception {
		if ((this.yearVacationRule == null)
				|| (this.yearVacationRule.getId() == null)) {
			return;
		}

		FilterInfo filter = new FilterInfo();
		filter.getFilterItems().add(
				new FilterItemInfo("yvRule.id", this.yearVacationRule.getId()
						.toString()));

		if (!YearVacationPersonFactory.getRemoteInstance().exists(filter)) {
			return;
		}

		IProgTask prog = new IProgTask() {
			public Object exec() throws Exception {
				int year = YearVacationEditUI.this.getInitYear();
				if (year == -1) {
					MsgBox.showInfo(EASResource.getString(
							"com.kingdee.eas.hr.time.TimeResource",
							"FIRST_INIT_YEAR"));

					SysUtil.abort();
				}
				IObjectPK logPK = LogUtil
						.beginLog(null, "", new YearVacationRuleInfo()
								.getBOSType(), null,
								YearVacationEditUI.this.yearVacationRule
										.getName()
										+ "", "YearManager_initRule");

				IYearVacationBalance iyvBalance = YearVacationBalanceFactory
						.getRemoteInstance();

				iyvBalance.initYearVacation(
						YearVacationEditUI.this.yearVacationRule.getId()
								.toString(), year, true);

				LogUtil.afterLog(null, logPK);
				return "";
			}

			public void afterExec(Object result) throws Exception {
				MsgBox
						.showInfo(EASResource.getString(
								"com.kingdee.eas.hr.time.TimeResource",
								"ININ_RULE_OK"));
			}
		};
		ProgDialog dialog = null;
		Window win = SwingUtilities.getWindowAncestor(this);
		if ((win instanceof Frame))
			dialog = new ProgDialog((Frame) win);
		else if ((win instanceof Dialog)) {
			dialog = new ProgDialog((Dialog) win);
		}
		dialog.setLongTimeTask(prog);
		dialog.show();
	}

	private int getInitYear() throws EASBizException, BOSException {
		IHRInit iHR = HRInitFactory.getRemoteInstance();
		return iHR.getInitYear();
	}

	protected FilterInfo getDefaultFilterForQuery() {
		FilterInfo filter = new FilterInfo();
		filter.getFilterItems().add(
				new FilterItemInfo("hrOrgUnit.id", SysContext.getSysContext()
						.getCurrentHRUnit().getId().toString()));

		return filter;
	}

	@Override
	protected void tblAgeQuanSegment_editStopped(KDTEditEvent e)
			throws Exception {
		int rowIndex = e.getRowIndex();
		int colIndex = e.getColIndex();

		if (colIndex == 3 || colIndex == 4) {
			Object objYV = this.tblAgeQuanSegment.getRow(rowIndex).getCell(3)
					.getValue();
			Object objEV = this.tblAgeQuanSegment.getRow(rowIndex).getCell(4)
					.getValue();

			if (objYV != null && objEV != null) {
				this.tblAgeQuanSegment.getRow(rowIndex).getCell("colCounts")
						.setValue(
								Float.parseFloat(objYV.toString())
										+ Float.parseFloat(objEV.toString()));
			} else if (objYV != null && objEV == null) {
				this.tblAgeQuanSegment.getRow(rowIndex).getCell("colCounts")
						.setValue(Float.parseFloat(objYV.toString()));
			} else if (objEV != null && objYV == null) {
				this.tblAgeQuanSegment.getRow(rowIndex).getCell("colCounts")
						.setValue(Float.parseFloat(objEV.toString()));
			}
		}
	}
}